/**
 * Demonstrates a range of Button options the framework offers out of the box
 */
Ext.define('cloud.view.order.Order', {
    extend: 'Ext.Container',
    xtype: 'order',
    requires: ['Ext.List', 'Ext.TitleBar', 'Ext.field.Select', 'Ext.field.Search', 'Ext.plugin.PullRefresh', 'Ext.plugin.ListPaging'],
    config: {
        layout: 'vbox',
        items: [
            {
                xtype: 'toolbar',
                ui: 'dark',
                docked: 'top',
                style: '-webkit-box-shadow:1px 1px 3px #ccc;' +
                    'margin-bottom:6px;background:#FFFFFF;border:0px',
                items: [
                    {
                        xtype: 'titlebar',
                        docked: 'top',
                        cls: 'titleone',
                        items: [
                            {
                                xtype: 'button',
                                text: '返回',
                                id: 'titlebar',
                                hidden: true,
                                handler: function () {
                                    Ext.getCmp('orderstore').setHidden(false);
                                    Ext.getCmp('orderstoreFind').setHidden(true);
                                    Ext.getCmp('titlebar').setHidden(true);
                                    Ext.getCmp('search_order').setValue('');
                                }
                            },
                            {
                                xtype: 'textfield',
                                id: 'search_order',
                                width: '300px',
                                placeHolder: '请输入姓名/\手机/\订单号'
                                //style: 'padding-left:30px;'
                            },
                            {
                                xtype: 'button',
                                text: '打印订单',
                                id: 'print'
                            }
                        ]
                    }

                ]
            },
            {
                id: 'order_title',
                html: '<table class="tabclass tabclassHtml">' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="allcheck" id="allcheck" />全选</td>' +
                    '<td>姓名</td>' +
                    '<td>电话</td>' +
                    '<td>时间( 定 / 送 )</td>' +
                    '<td>地址</td>' +
                    '<td>品种</td>' +
                    '<td>总价</td>' +
                    '<td>支付方式</td>' +
                    '<td>目前状况</td>' +
                    '<td style="min-width:120px;">操作</td>' +
                    '</tr>' +
                    '</table>',
                listeners: {
                    painted: function (label) {
                        label.on('tap', function (target, event) {
                            if (!Ext.getCmp('orderstore').getHidden()) {
                                var input = document.getElementsByName('record');
                            } else {
                                var input = document.getElementsByName('search_record');
                            }
                            if (target.target.name == 'allcheck') {
                                for (i = 0; i < input.length; i++) {
                                    if (!event.checked) {
                                        input[i].checked = true
                                    } else {
                                        input[i].checked = false
                                    }
                                }
                            }
                            return false;
                        }, this);
                    }
                }
            },

            {
                xtype: 'list',
                store: 'Order',
                id: 'orderstore',
                emptyText: '木有数据',
                pressedCls: false,
                selectedCls: true,
                cls: 'x-list3',
                flex: 1,
                itemTpl: '<table class="tabclass">' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="record" value="{coid}" /></td>' +
                    '<td>{consignee}</td>' +
                    '<td>{otel}</td>' +
                    '<td>{[Ext.Date.format(new Date(parseInt(values.createtime) * 1000), "Y-m-d H:i")]}<br>{takedate} {[values.taketime.substr(0,5)]}</td>' +
                    '<td>{takeaddress}</td>' +
                    '<td><tpl for="products"><p>{pname}/{sname}<br></p></tpl></td>' +
                    '<td>{totalmoney} ￥</td>' +
                    '<td>{paymenttype}<tpl if="paymenttype!=\'货到付款\' ">({paymentstatus})</tpl></td>' +
                    '<td>{status}</td>' +
                    '<td style="min-width:120px;"><input type="button" value="详情" name="detail" /></td>' +
                    '</tr>' +
                    '</table>',
                plugins: [
                    {
                        xclass: 'Ext.plugin.PullRefresh',
                        pullRefreshText: '下拉可以更新',
                        releaseRefreshText: '松开开始更新',
                        style: 'top:12px',
                        loadingText: '正在刷新……',
                        refreshFn: function (loaded, arguments) {
                            //loaded.getList().getStore().getProxy().setExtraParams({'cadid':localStorage.getItem('cadid'),'param':'0'});
                            loaded.getList().getStore().loadPage(1, {
                                callback: function (record, operation, success) {
                                    Ext.Viewport.unmask();
                                }, scope: this });
                        }
                    },
                    {
                        xclass: 'Ext.plugin.ListPaging',
                        loadMoreText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">点击加载更多。。。。</h2>',
                        noMoreRecordsText: '<h2 style="text-align: center; padding-top: 20px; padding-bottom: 20px;">没有更多条记录了</h2>',
                        autoPaging: false //设置为TRUE将自动触发
                    }
                ],

                listeners: {
                    painted: function () {
                        // if (Ext.getStore('Order').getData().length == 0) {
                        Ext.getStore('Order').getProxy().setExtraParams({'cadid': localStorage.getItem('cadid'), 'param': '0'});
                        Ext.getStore('Order').loadPage(1);
                        //}
                        //Ext.getStore('Order').clearFilter();
                    }
                }
            },
            {
                xtype: 'list',
                store: 'Order',
                id: 'orderstoreFind',
                style: 'font-size:12px;',
                hidden: true,
                emptyText: '木有数据',
                pressedCls: false,
                selectedCls: false,
                cls: 'x-list3',
                flex: 1,
                itemTpl: '<table class="tabclass">' +
                    '<tr>' +
                    '<td style="max-width: 20px;"><input type="checkbox" name="record" value="{coid}" /></td>' +
                    '<td>{consignee}</td>' +
                    '<td>{otel}</td>' +
                    '<td>{[Ext.Date.format(new Date(parseInt(values.createtime) * 1000), "Y-m-d H:i")]}<br>{takedate} {[values.taketime.substr(0,5)]}</td>' +
                    '<td>{takeaddress}</td>' +
                    '<td><tpl for="products">{pname} / {sname}<br></tpl></td>' +
                    '<td>{totalmoney} ￥</td>' +
                    '<td>{paymenttype}<tpl if="paymenttype!=\'货到付款\' ">({paymentstatus})</tpl></td>' +
                    '<td>{status}</td>' +
                    '<td><input type="button" value="详情" name="detail" /></td>' +
                    '</tr>' +
                    '</table>'
            }
        ]
    }
})
;